//
//  GYUserFeedbackViewController.m
//  GoodLuck
//
//  Created by apple on 2018/3/2.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYUserFeedbackViewController.h"
#import "GYNetWorkTools.h"

@interface GYUserFeedbackViewController ()<UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UITextView *faceBackTextView;
@property (weak, nonatomic) IBOutlet UIButton *submitBtu;
@property (weak, nonatomic) IBOutlet UILabel *PromptLable;

@end

@implementation GYUserFeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"用户反馈";
    self.submitBtu.layer.cornerRadius = 4;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.faceBackTextView resignFirstResponder];
}

- (IBAction)submitClick {
    if (self.faceBackTextView.text.length != 0) {
        [GYNetWorkTools requestUserFeedback:self.faceBackTextView.text success:^(NSDictionary *obj) {
            int code = [[obj objectForKey:@"code"] intValue];
            if (code == 200) {
                NSLog(@"提交成功..");
                [EasyTextView showSuccessText:@"提交成功!"];
                [self.navigationController popViewControllerAnimated:YES];
            }else if(code == 400) {
                [EasyTextView showText:@"提交失败"];
            }
        } error:^(NSError *error) {
            [EasyTextView showText:@"提交失败"];
            NSLog(@"submit feedback failed===%@",error);
        }];
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:NO];
}

#pragma mark -- UITextViewDelegate

- (void)textViewDidBeginEditing:(UITextView *)textView {
    self.PromptLable.hidden = YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    self.PromptLable.hidden = [textView hasText];
}
@end
